package com.example.mqdemo.Work.fairDispatch;

import jakarta.annotation.Resource;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;

/*
 *@description: 工作队列消息公平分发发送者
 *@author: hisen
 *@Time: 2023/11/21  10:05
 */
@Component("fairWorkProducer")
public class WorkProducer {
    @Resource
    AmqpTemplate amqpTemplate;

    public void sendMessage(String message) {
        // 发送消息到名为 "work" 的队列
        for (int i = 1; i <= 10; i++) {
            amqpTemplate.convertAndSend("fair-dispatch_work", message + i);
        }
        System.out.println("发送消息: " + message);
    }
}